package com.situ.mall.config;


import com.situ.mall.converter.String2DateConverter;
import com.situ.mall.interceptor.LoginInterceptor;
import com.situ.mall.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private UserMapper userMapper;

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(new String2DateConverter());
    }

    //配置虚拟路径
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/pic/**")
                .addResourceLocations("file:/D:/mypic/");
        WebMvcConfigurer.super.addResourceHandlers(registry);
    }


    //用这个方法来配置拦截器，我们写的拦截器只有配置了才起作用
   /* @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //链式编程
        //把登录的拦截器配置上才能起作用
        // addPathPatterns("/**") 拦截器拦截所有的请求,包括static下面静态资源
        // excludePathPatterns 代表哪些请求不需要拦截
        registry.addInterceptor(new LoginInterceptor(userMapper))
                .addPathPatterns("/**")
                .excludePathPatterns("/page/login", "/user/login", "/user/logout", "/static/**");
    }*/
}
